package com.ymatou.iapi.livebuyer.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.ChatMsgDto;
import com.ymatou.iapi.livebuyer.parameter.GetLiveChatMsgListBean;
import com.ymatou.iapi.livebuyer.service.GetLiveChatMsgListCall;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
/**
*查询直播间互动消息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetLiveChatMsgList{
	private static GetLiveChatMsgListBean getlivechatmsglistBean;
	private static GetLiveChatMsgListCall getlivechatmsglistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询直播间互动消息");
	}

	@Before
	public void caseUp() {
		getlivechatmsglistBean=new GetLiveChatMsgListBean();
		getlivechatmsglistCall=new GetLiveChatMsgListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getlivechatmsglistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetLiveChatMsgList_001() {
		Logger.start(true,"查询直播间互动消息成功");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			String groupid=LiveRoomCallService.CreateGroup("CallbackAfterSendMsg:"+TestDataManager.getRandomNum(5),createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.getLiveDto().setGroupId(groupid);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			LiveRoomCallService.SellerLiveOnline(liveroom.getId(), liveroom.getUserId());
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer uid=urrc.getUserid();
			LiveRoomCallService.SaveLiveNotice(liveroom.getId(), "content");
			String logoimg="http://www.ymatou.com/test2.jpg";
			int crown=1;
			int newComer=1;
			int level=2;
			LiveRoomCallService.CallbackAfterSendMsg(groupid, uid, "消息:","{\"headPic\":\""+logoimg+"\""
					+ ",\"userAction\":1,\"userId\":\""+uid+"\",\"nickName\":\""+regbean.getLoginId()+"\",\"buyerLevel\":\""+level+"\",\"crown\":\""+crown+"\",\"newComer\":\""+newComer+"\"}");

			LiveRoomCallService.enterGroup(liveroom.getId(), 1);
			LiveRoomCallService.PublishLiveStatCall(liveroom.getId());
			//异步写入日志
			Thread.sleep(1000);
			getlivechatmsglistBean.setLiveId(liveroom.getId());
			getlivechatmsglistBean.setStayBeginTime(YMTDateUtil.getBeforeOrNextMunite(-1));
			getlivechatmsglistBean.setStayEndTime(YMTDateUtil.getBeforeOrNextMunite(2));
			getlivechatmsglistCall.setData(getlivechatmsglistBean);
			getlivechatmsglistCall.callService();			
			Logger.verifyEquals("200", getlivechatmsglistCall.getString("code"), "验证code");
			List<ChatMsgDto> chats = getlivechatmsglistCall.getChatMsgDtos();
			Logger.verifyEquals(1, chats.size(), "验证记录");
			Logger.verifyEquals(crown, chats.get(0).getCrown(), "验证crown");
			Logger.verifyEquals(level, chats.get(0).getLevel(), "验证Level");
			Logger.verifyEquals("消息:", chats.get(0).getMsg(), "验证crown");
			Logger.verifyEquals(newComer, chats.get(0).getNewComer(), "验证NewComer");
			Logger.verifyEquals(regbean.getLoginId(), chats.get(0).getNick(), "验证Nick");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetLiveChatMsgList_002() {
		Logger.start(true,"不输入liveId失败");
		try {
//			getlivechatmsglistBean.setLiveId(liveroom.getId());
			getlivechatmsglistBean.setStayBeginTime(YMTDateUtil.getBeforeOrNextMunite(-1));
			getlivechatmsglistBean.setStayEndTime(YMTDateUtil.getBeforeOrNextMunite(2));
			getlivechatmsglistCall.setData(getlivechatmsglistBean);
			getlivechatmsglistCall.callService();			
			Logger.verifyEquals("100", getlivechatmsglistCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetLiveChatMsgList_003() {
		Logger.start(true,"不输入stayBeginTime失败");
		try {
			getlivechatmsglistBean.setLiveId(1);
//			getlivechatmsglistBean.setStayBeginTime(YMTDateUtil.getBeforeOrNextMunite(-1));
			getlivechatmsglistBean.setStayEndTime(YMTDateUtil.getBeforeOrNextMunite(2));
			getlivechatmsglistCall.setData(getlivechatmsglistBean);
			getlivechatmsglistCall.callService();			
			Logger.verifyEquals("100", getlivechatmsglistCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetLiveChatMsgList_004() {
		Logger.start(true,"不输入stayEndTime失败");
		try {
			getlivechatmsglistBean.setLiveId(1);
			getlivechatmsglistBean.setStayBeginTime(YMTDateUtil.getBeforeOrNextMunite(-1));
//			getlivechatmsglistBean.setStayEndTime(YMTDateUtil.getBeforeOrNextMunite(2));
			getlivechatmsglistCall.setData(getlivechatmsglistBean);
			getlivechatmsglistCall.callService();			
			Logger.verifyEquals("100", getlivechatmsglistCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}